package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author shkstart
 * @create 2023-02-27-23:23
 */
@Controller

public class RespController {

    //请求转发2
    @RequestMapping("/fw2")
    public void forward(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("hello.html").forward(request,response);

    }
    //请求重定向2
    @RequestMapping("/rt2")
    public void redirect2(HttpServletResponse response) throws IOException {
        response.sendRedirect("hello.html");
    }
    //请求转发
    @RequestMapping("/fw")
    public Object forward() {
        return "forward:hello.html";
    }
    // 请求重定向
    @RequestMapping("/rt")
    public Object redirect(){
        return "redirect:hello.html";
    }
    @RequestMapping("/index")
    @ResponseBody
    public String getIndex(){
        return "index.html";
    }
}
